let form = document.querySelector('form');
let tip  = form.querySelector('.tips');
let arr = [true,true,true];
let persons = [
    { "username":"12345678901","password":"1111" },
    { "username":"22345678901","password":"222" },
    { "username":"32345678901","password":"33333" },
]
//1.手机号
let reg = /^1\d{10}$/;
form.tel.onblur = function () {
    if (reg.test(this.value)) {
        tip.style.display = "none";
        arr[0] = true;
        
    } else {
        tip.style.display = "block";
        arr[0] = false;
    }
}

//2.密码
let reg1 = /^\w{6}$/;
form.pass.onblur = function () {
    if (reg1.test(this.value)) {
        tip.style.display = "none"
        arr[1] = true;
    } else {
        tip.style.display = "block"
        arr[1] = false;
    }
}

//3.确认密码
form.pass2.onblur = function () {
    if (this.value == form.pass2.value) {
        tip.style.display = "none"
        arr[2] = true;
    } else {
        tip.style.display = "block"
        arr[2] = false;
    }
}

let registerbtn = form.querySelector(".registerbtn");
registerbtn.onclick = function(){
    form.tel.focus();
    form.tel.blur();
    form.pass.focus();
    form.pass.blur();
    form.pass2.focus();
    form.pass2.blur();
    console.log(form.tel.value,form.pass.value);
    console.log(persons.some(i=>i.username===form.tel.value))
    if(persons.some(i=>i.username===form.tel.value)){
        alert("账号已存在");
    }else{
        // persons.push({username:form.tel.value,password:form.pass.value});
        // console.log(persons);
        persons=[...persons,{username:form.tel.value,password:form.pass.value}];
        console.log(persons);
        alert("注册成功");
        location.href = "login.html";
    }
    return false;
}
